//
// Created by 123 on 2024/2/28.
//
#include <iostream>

using namespace std;
#define MAXSIZE 10


//静态分配
typedef struct {
    int data[MAXSIZE];
    int length;
} SqList_static;

void initList_static(SqList_static &L);

void showList_static(SqList_static L);

bool listInsert(SqList_static &L, int i, int e);

bool listDelete(SqList_static &L, int i, int &e);

int getElem(SqList_static L, int i);

int localeElem(SqList_static L, int e);

int main() {
    SqList_static L;
    initList_static(L);
    listInsert(L, 1, 1);
    listInsert(L, 2, 2);
    listInsert(L, 3, 3);
    listInsert(L, 4, 4);
    listInsert(L, 5, 5);


    showList_static(L);
    listInsert(L, 1, 01);

    listInsert(L, 2, 11);
    showList_static(L);


    int e = -1;
    listDelete(L,1,e);
    listDelete(L,1,e);
    cout<<e<<endl;
    showList_static(L);

    return 0;
}

void initList_static(SqList_static &L) {
    for (int i = 0; i < MAXSIZE; i++) {
        L.data[i] = 0;
    }
    L.length = 0;
}

void showList_static(SqList_static L) {
    for (int i = 0; i < MAXSIZE; ++i) {
        cout << L.data[i] << "  ";
    }
    cout << endl;
}

bool listInsert(SqList_static &L, int i, int e) {
    if (i < 1 || i > L.length + 1)
        return false;
    if (L.length > MAXSIZE)
        return false;
    for (int j = L.length; j >= i; j--)
        L.data[j] = L.data[j - 1];
    L.data[i - 1] = e;
    L.length++;
    return true;
}

bool listDelete(SqList_static &L, int i, int &e) {
    if (i > L.length)
        return false;
    if (L.length == 0)
        return false;
    e = L.data[i - 1];
    for (int j = i; j < L.length; ++j)
        L.data[j-1] = L.data[j];
    L.length--;
    return true;
}

int getElem(SqList_static L, int i) {
    return L.data[i - 1];
}

int localeElem(SqList_static L, int e) {
    for (int i = 0; i < L.length; ++i) {
        if (L.data[i] == e)
            return i + 1;
    }
    return -1;
}
